package com.shine.icis.action;


import java.util.Date;

import com.shine.cotrun.sql.QueryParameters;
import com.shine.cotrun.web.comm.ListPage;
import com.shine.cotrun.web.util.DataFormatUtil;
import com.shine.esim.struts.webutil.SessionParam;
import com.shine.icis.blo.IAllotmentConfService;
import com.shine.icis.config.SysConstants;
import com.shine.icis.exception.ICISException;
import com.shine.icis.hbean.AllotmentConf;
import com.shine.icis.util.EFRameInf;

public class AllotmentConfAction extends BaseAction {

	/**
	 * 上海配股配置
	 */
	private static final long serialVersionUID = 7638121893867812633L;
	
	private IAllotmentConfService allotmentConfService;
	
	// input param
	private int pageNo;
	private int pageSize;
	
	private String confId;
	private String secCode;
	private String allCode;
	private String startDate;
	private String endDate;
	//output value
	private ListPage<AllotmentConf> allotmentConfPage;
	
	public void setAllotmentConfService(IAllotmentConfService allotmentConfService) {
		this.allotmentConfService = allotmentConfService;
	}

	public void setPageNo(int pageNo) {
		this.pageNo = pageNo;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public void setConfId(String confId) {
		this.confId = confId;
	}

	public void setSecCode(String secCode) {
		this.secCode = secCode;
	}

	public void setAllCode(String allCode) {
		this.allCode = allCode;
	}

	public void setStartDate(String startDate) {
		this.startDate = startDate;
	}

	public void setEndDate(String endDate) {
		this.endDate = endDate;
	}

	public ListPage<AllotmentConf> getAllotmentConfPage() {
		return allotmentConfPage;
	}

	/**
	 * 进入查询页面
	 * @return
	 */
	public String initQueryAllotmentConf() {
		return success();
	}
	
	/**
	 * 查询
	 * @return
	 */
	public String queryAllotmentConf() {
		QueryParameters qp = new QueryParameters();
		
		//设置分页信息
		qp.setPageNo(pageNo);
		qp.setPageSize(pageSize);
		//排序信息
		qp.addOrder("confId", true);
		try {
			allotmentConfPage = this.allotmentConfService.getAllotmentConfPage(qp);
			return success();
		} catch(Exception e) {
			e.printStackTrace();
			return error();
		}
	}
	
	/**
	 * 新增
	 * @return
	 */
	public String addAllotmentConf() {
		if (secCode == null || secCode.trim().equals("")
				|| allCode == null || allCode.trim().equals("")
				|| startDate == null 
				|| endDate == null) {
			return error("参数不能为空");
		}
		boolean success = false;
		SessionParam user = (SessionParam)getSession().getAttribute(SysConstants.SESSION_USER_KEY);
		try {
			AllotmentConf conf = new AllotmentConf();
			conf.setSecCode(secCode);
			conf.setAllCode(allCode);
			conf.setStartDate(Integer.parseInt(startDate.replaceAll("-","")));
			conf.setEndDate(Integer.parseInt(endDate.replaceAll("-","")));
			Date nowDate = new Date();
			String operDate = DataFormatUtil.noNullValue(nowDate,"yyyy-MM-dd").replaceAll("-","");
			String operTime = DataFormatUtil.noNullValue(nowDate,"HH:mm:ss").replaceAll(":","");
			conf.setOperDate(Integer.parseInt(operDate));
			conf.setOperTime(Integer.parseInt(operTime));
			this.allotmentConfService.addAllotmentConf(conf);
			success = true;
			return success();
		} catch(ICISException e) {
			return error(e.getMessage());
		} catch(Exception e) {
			e.printStackTrace();
			return error();
		} finally {
			//记录系统日志
			EFRameInf.saveOpLog(user.getUSER_CODE(),EFRameInf.FUNCCODE_BUSICONF, "增加上海配股信息", success);
		}
	}
	/**
	 * 修改A13信息
	 * @author zhangxr
	 * @return
	 */
	public String modifyAllotmentConf() {
		if (confId == null || secCode == null || secCode.trim().equals("")
				|| allCode == null || allCode.trim().equals("")
				|| startDate == null 
				|| endDate == null) {
			return error("参数不能为空");
		}
		boolean success = false;
		SessionParam user = (SessionParam)getSession().getAttribute(SysConstants.SESSION_USER_KEY);
		try {
			AllotmentConf conf = new AllotmentConf();
			conf.setConfId(Integer.parseInt(confId));
			conf.setSecCode(secCode);
			conf.setAllCode(allCode);
			conf.setStartDate(Integer.parseInt(startDate.replaceAll("-","")));
			conf.setEndDate(Integer.parseInt(endDate.replaceAll("-","")));
			Date nowDate = new Date();
			String operDate = DataFormatUtil.noNullValue(nowDate,"yyyy-MM-dd").replaceAll("-","");
			String operTime = DataFormatUtil.noNullValue(nowDate,"HH:mm:ss").replaceAll(":","");
			conf.setOperDate(Integer.parseInt(operDate));
			conf.setOperTime(Integer.parseInt(operTime));
			this.allotmentConfService.modifyAllotmentConf(conf);
			success = true;
			return success();
		} catch(ICISException e) {
			return error(e.getMessage());
		} catch(Exception e) {
			e.printStackTrace();
			return error();
		} finally {
			//记录系统日志
			EFRameInf.saveOpLog(user.getUSER_CODE(),EFRameInf.FUNCCODE_BUSICONF, "修改上海配股信息", success);
		}
	}
	
	/**
	 * 删除
	 * @return
	 */
	public String deleteAllotmentConf() {
		if (confId == null) {
			return error("参数不能为空");
		}
		boolean success = false;
		SessionParam user = (SessionParam)getSession().getAttribute(SysConstants.SESSION_USER_KEY);
		try {
			this.allotmentConfService.deleteAllotmentConf(Integer.parseInt(confId));
			success = true;
			return success();
		} catch(Exception e) {
			e.printStackTrace();
			return error();
		} finally {
			//记录系统日志
			EFRameInf.saveOpLog(user.getUSER_CODE(), EFRameInf.FUNCCODE_BUSICONF, "删除上海配股信息", success);
		}
	}
}
